package com.tenebrous.jestic.compents.filter;

import cn.hutool.core.date.DateUtil;
import com.tenebrous.jestic.entity.framwork.meber.organ.OrgUser;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;

/**
 * @Classname InterfaceFilter
 * @Description TODO
 * @Date 2022/12/4 6:22 PM
 * @Created by zhangya
 */
@Slf4j
public class InterfaceFilter implements Filter {

  private final String noToken = "" +
          "/api/portal/jestic/remote/v1/decrypt," +
          "/api/portal/jestic/remote/v1/authority," +
          "/api/portal/jestic/remote/v1/heartBeat";

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    String sessionid = req.getSession().getId();
    OrgUser ouser = (OrgUser) req.getSession().getAttribute(sessionid);
    String uri = req.getRequestURI();
    if (Objects.isNull(ouser)) {
      boolean contains = noToken.contains(uri);
      if (contains) {
        filterChain.doFilter(request, response);
      }
    } else {
      filterChain.doFilter(request, response);
    }
  }
}
